package com.wm.wmcrm.sys.controller;

import com.wm.wmcrm.common.annotation.SystemLog;
import com.wm.wmcrm.common.util.PageUtils;
import com.wm.wmcrm.sys.entity.SysRole;
import com.wm.wmcrm.sys.model.SysRoleQueryDTO;
import com.wm.wmcrm.sys.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static java.lang.Thread.sleep;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author wm
 * @since 2023-02-11
 */
@Api(tags = "系统角色",value = "SysRole")
@RestController
@RequestMapping("/sys/sysRole")
public class SysRoleController {
    @Resource
    private ISysRoleService roleService;

    @ApiOperation(value = "查询分页角色",notes = "角色信息")
    @GetMapping("/list")
    public PageUtils list(@ApiParam(value = "查询的条件")SysRoleQueryDTO queryDTO){
        return roleService.queryPage((queryDTO));
    }

    @SystemLog("添加角色")
    @ApiOperation(value = "添加角色",notes = "角色用户")
    @PostMapping("/save")
    public boolean save(@RequestBody SysRole sysRole){
        return roleService.saveRole(sysRole);
    }
    @SystemLog("删除角色")
    @ApiOperation(value = "删除角色",notes = "角色用户")
    @GetMapping("/deleteOne")
    public boolean deleteOne(String roleId){
        return roleService.deleteOne(roleId);
    }

    @ApiOperation(value = "检查用户名字是否存在",notes = "用户名字是否存在")
    @GetMapping("/checkNameExist")
    public int checkNameExist(String roleName){
        return roleService.checkNameExist(roleName);
    }

    @SystemLog("批量删除角色")
    @ApiOperation(value = "批量删除用户角色",notes = "批量删除用户角色")
    @PostMapping("/deleteList")
    public int deleteList(@RequestBody List<String> roleIdList){
        return roleService.deleteBatch(roleIdList);
    }

    @SystemLog("更新用户角色")
    @ApiOperation(value = "更新用户角色",notes = "用户角色")
    @PostMapping("/updateOne")
    public boolean updateOne(@RequestBody SysRole sysRole ){
        return roleService.updateOne(sysRole);
    }

}
